package com.xjcs.saplingplan.dialog

import android.content.Context
import com.lxj.xpopup.core.CenterPopupView
import com.xjcs.saplingplan.R
import com.xjcs.saplingplan.const.setSingleClick
import com.xjcs.saplingplan.databinding.PopBaseCenterBinding

class BaseCenterPop(
    context: Context,
    private val title: String,
    private val content: String,
    private val resultCallback: () -> Unit
) : CenterPopupView(context) {

    private lateinit var binding: PopBaseCenterBinding

    override fun getImplLayoutId(): Int {
        return R.layout.pop_base_center
    }

    override fun onCreate() {
        super.onCreate()
        binding = PopBaseCenterBinding.bind(contentView)

        if (title.isNotEmpty()) {
            binding.tvTitle.text = title
        }
        if (content.isNotEmpty()) {
            binding.tvContent.text = content
        }
        binding.tvCancel.setSingleClick {
            dialog.dismiss()
        }

        binding.tvSure.setSingleClick {
            resultCallback.invoke()
            dialog.dismiss()
        }
    }
}